const mongoose = require('mongoose');

const Schema = mongoose.Schema;

const schema = new mongoose.Schema({
  name: Schema.Types.String,
  age: Schema.Types.Number,
  gender: Schema.Types.Number,
  createdAt: Schema.Types.Date,
  updatedAt: Schema.Types.Date,
});

schema.pre('save', function (next) {
  if (this.isNew) {
    this.createdAt = new Date;
  } else {
    this.updatedAt = new Date;
  }
  next();
});



const UserModel = mongoose.model('user', schema);

module.exports = UserModel;

